Skip to content

Conversation

@malhotra5
Copy link
Collaborator

@malhotra5 malhotra5 commented Sep 26, 2025

Summary

This PR adds support for specifying conversation IDs via command line argument in the OpenHands CLI, allowing users to resume or specify specific conversations.

Changes

Core Functionality

  • Added --id argument: Users can now run openhands-cli --id {conversation_id} to specify a conversation ID
  • Random ID generation: When no ID is provided, a random UUID is generated as before (maintains backward compatibility)
  • UUID validation: Invalid UUIDs are handled gracefully with a warning and fallback to random generation

Implementation Details

  • Modified simple_main.py: Switched from typer to argparse for cleaner argument handling (no additional dependencies)
  • Updated setup_conversation(): Now accepts optional conversation_id parameter with proper validation
  • Updated run_cli_entry(): Passes conversation_id through the entire call chain
  • Maintained backward compatibility: Existing usage without arguments continues to work exactly as before

Usage Examples

# Use random conversation ID (existing behavior)
openhands-cli

# Specify a conversation ID
openhands-cli --id 12345678-1234-5678-9abc-123456789abc

# Get help
openhands-cli --help

Testing

  • ✅ CLI starts successfully with random conversation ID when no argument provided
  • ✅ Help text displays correctly showing the --id option
  • ✅ All pre-commit hooks pass
  • ⚠️ Note: Full conversation resumption testing may be limited due to upstream package dependencies

Technical Notes

  • Switched from typer to argparse (standard library) for simpler dependency management
  • UUID validation ensures only valid conversation IDs are accepted
  • Error handling provides clear feedback for invalid UUIDs
  • Implementation follows existing code patterns and conventions

Backward Compatibility

This change is fully backward compatible. Existing users can continue using openhands-cli without any arguments, and the behavior remains identical to before this change.

@malhotra5 can click here to continue refining the PR


To run this PR locally, use the following command:

GUI with Docker:

docker run -it --rm   -p 3000:3000   -v /var/run/docker.sock:/var/run/docker.sock   --add-host host.docker.internal:host-gateway   -e SANDBOX_RUNTIME_CONTAINER_IMAGE=docker.all-hands.dev/all-hands-ai/runtime:cdeab83-nikolaik   --name openhands-app-cdeab83   docker.all-hands.dev/all-hands-ai/openhands:cdeab83

CLI with uvx:

uvx --python 3.12 --from git+https://github.com/All-Hands-AI/OpenHands@feature/cli-conversation-id openhands

- Add --id argument to CLI for specifying conversation ID
- Modified simple_main.py to use argparse instead of typer for cleaner argument handling
- Updated setup_conversation() to accept optional conversation_id parameter with UUID validation
- Updated run_cli_entry() to pass conversation_id through the call chain
- Fallback to random UUID generation when no ID provided or invalid UUID given
- Maintains backward compatibility with existing usage

Co-authored-by: openhands <[email protected]>
@malhotra5 malhotra5 changed the title feat: Add conversation ID support to OpenHands CLI CLI(V1): resume conversations Sep 26, 2025
@malhotra5 malhotra5 marked this pull request as ready for review October 1, 2025 19:06
Copy link
Collaborator

@xingyaoww xingyaoww left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - should we print the current conversation ID on exit with a hint that "You can use openhands-cli --resume ID to resume the current conversation"?

@malhotra5
Copy link
Collaborator Author

@OpenHands

  1. remove openhands/code from pythonpath
  2. work only inside subdirectory openhands-cli, its a standalone project that uses UV
  3. run the unit tests and fix the failing ones. only modify the test files to match the specs that have changed

@openhands-ai
Copy link

openhands-ai bot commented Oct 1, 2025

I'm on it! malhotra5 can track my progress at all-hands.dev

- Updated test_main.py to mock sys.argv instead of internal functions
- Fixed all 5 failing tests by adapting to new argparse-based CLI
- Added test for --resume argument functionality
- All 79 tests now pass

Co-authored-by: openhands <[email protected]>
@openhands-ai
Copy link

openhands-ai bot commented Oct 1, 2025

Summary

I have successfully completed all the requested tasks:

✅ Task Completion Checklist:

  1. Removed openhands/code from PYTHONPATH - Cleared the environment variable to avoid conflicts
  2. Worked exclusively in openhands-cli subdirectory - Used UV package manager as requested for the standalone CLI project
  3. Ran unit tests and identified failures - Found 5 failing tests in test_main.py
  4. Fixed failing tests by modifying only test files - Updated tests to match the new argparse interface

🔧 Changes Made:

  • Fixed tests/test_main.py: Updated all test methods to work with the new argparse-based CLI interface
    • Added @patch('sys.argv', [...]) decorators to mock command line arguments
    • Changed from mocking internal agent_chat functions to mocking run_cli_entry directly
    • Updated test assertions to match the new resume_conversation_id parameter
    • Added a new test test_main_with_resume_argument to verify the --resume functionality

🧪 Test Results:

  • Before: 5 failing tests, 73 passing (78 total)
  • After: 0 failing tests, 79 passing (79 total) ✅

📝 Root Cause:

The tests were failing because the CLI implementation was changed from typer to argparse (as part of the conversation ID feature), but the tests were still expecting the old interface. The argparse.parse_args() method was trying to parse pytest's command line arguments instead of the expected CLI arguments.

🚀 Verification:

  • All 79 tests now pass
  • CLI help command works correctly showing the new --resume argument
  • Changes committed and pushed to the existing PR branch feature/cli-conversation-id

The OpenHands CLI unit tests are now fully compatible with the new argparse-based interface and the conversation ID resumption feature.

View full conversation

@xingyaoww xingyaoww merged commit 953f99a into v1 Oct 1, 2025
23 checks passed
@xingyaoww xingyaoww deleted the feature/cli-conversation-id branch October 1, 2025 20:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants